import {defineStore} from "pinia";
import {ref} from "vue"
import type {IResCommodityData, IResData} from "@/types";
import ajax from "@/axios";

export const useCommodity = defineStore("commodity", () => {
  const data = ref<Array<IResCommodityData>>([])

  function getCommodity() {
    ajax<IResData<Array<IResCommodityData>>>({
      url: '/admin/pro/list',
      method: 'get',
      headers: {
        token: localStorage.getItem('adminToken'),
      }
    }).then(r => {
      data.value = r.data.data
      console.log(r.data)
    })
  }

  getCommodity()
  return {data, getCommodity}
})
